package com.xiangxg.jvm.classloader;

public class MyTest6 {
    public static void main(String[] args) {
        Singletion singletion = Singletion.getInstance();
        System.out.println("counter1: "+Singletion.counter1);
        System.out.println("counter2: "+Singletion.counter2);

    }
}
class Singletion{
    public static int counter1;

    private static Singletion singletion= new Singletion();
    private Singletion(){
        counter1++;
        counter2++;//准备阶段的重要意义
        System.out.println(counter1);
        System.out.println(counter2);

    }
    //由于按声明顺序初始化，会把上面已经赋于1的值重新置为0
    public static int counter2 = 0;
    public static Singletion getInstance(){
        return singletion;
    }
}